<template>
  <div class="another-item" @click="toDetail">
    <div class="goods-img" style="min-height: 120px; min-width: 120px">
      <van-image lazy-load :src="'http://www.dsl2023hcy.love:3004' + goods_img"></van-image>
    </div>
    <!-- 商品信息 -->
    <div class="goods-content">
      <div class="goods-title">{{ goods_name }}</div>

      <div class="price">
        ￥<span class="number">{{ dealPrice(goods_price)[0] }}</span>
        <span>.{{ dealPrice(goods_price)[1] }}</span>
        元
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'goodsItem',
  props: {
    id: Number,
    goods_img: String,
    goods_name: String,
    goods_price: Number
  },
  methods: {
    // 前往商品详情页
    toDetail(id) {
      this.$router.push('/goods/detail/' + this.id)
    },
    // 处理价格
    dealPrice(price) {
      const priceArr = price.toFixed(2).split('.')
      return priceArr
    }
  }
}
</script>

<style lang="less" scoped>
.another-item {
  background-color: #fff;
  width: 48%;
  padding: 5px 5px 20px;
  margin-bottom: 10px;
  border-bottom-left-radius: 10px;
  border-bottom-right-radius: 10px;

  ::v-deep .van-image {
    width: 100%;
    height: auto;
  }
  .goods-img {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100px;
    min-width: 100px;
  }

  img {
    width: 100%;
    height: auto;
  }

  .goods-content {
    background-color: #fff;
    padding: 0 10px;

    .goods-title {
      margin-top: 10px;
      font-size: 14px;
      font-weight: 600;
      overflow: hidden;
      text-overflow: ellipsis; /*显示为......*/
      -webkit-line-clamp: 2; /*显示为两行，在第二行中显示为.......*/
      display: -webkit-box;
      -webkit-box-orient: vertical;
    }

    .price {
      margin-top: 5px;
      font-size: 12px;
      color: #ee0a24;
      padding-bottom: 10px;
      span {
        font-weight: 700;
      }

      .number {
        font-size: 16px;
      }
    }
  }
}
</style>
